package com.qianbao.qianbaobusiness.database;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.content.Context;

import com.baseandroid.config.Global;
import com.qianbao.qianbaobusiness.json.PcdBean;

@Database(entities = {PcdBean.ProvincesBean.class, PcdBean.CitysBean.class, PcdBean.DistrictsBean.class}, version = 1, exportSchema = false)
public abstract class PcdDatabase extends RoomDatabase {
    public abstract ProvinceDao provinceDao();

    public abstract CityDao cityDao();

    public abstract DistrictDao districtDao();


    private static final String DB_NAME = "pcd.db";
    private static volatile PcdDatabase instance;

    public static synchronized PcdDatabase getInstance(Context context) {
        if (instance == null) {
            instance = create(context);
        }
        return instance;
    }

    private static PcdDatabase create(final Context context) {
        return Room.databaseBuilder(
                context,
                PcdDatabase.class,
                DB_NAME).build();
    }
}